home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / kriegspi / xpieces.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-30  |  5.9 KB  |  243 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: xpieces.c,v 1.9 87/05/19 18:46:27 schoch Exp $";
  3. #endif
  4.  
  5. #include "externs.h"
  6.  
  7. #define piece_width 64
  8. #define piece_height 64
  9. #include "pawn.h"
  10. #include "pawn_mask.h"
  11. #include "bishop.h"
  12. #include "bishop_mask.h"
  13. #include "queen.h"
  14. #include "queen_mask.h"
  15. #include "king.h"
  16. #include "king_mask.h"
  17. #include "rook.h"
  18. #include "rook_mask.h"
  19. #include "knight.h"
  20. #include "knight_mask.h"
  21. #include "icon.h"
  22.  
  23. Pixmap icon_pixmap;
  24.  
  25. p_init()
  26. {
  27.     Pixmap mask, piece;
  28.     Bitmap bp;
  29.  
  30.     bp = XStoreBitmap(piece_width, piece_height, pawn_bits);
  31.     piece = XMakePixmap(bp, WhitePixel, BlackPixel);
  32.     XFreeBitmap(bp);
  33.     pieces_icons[PAWN] = piece;
  34.  
  35.     bp = XStoreBitmap(piece_width, piece_height, pawn_mask_bits);
  36.     mask = XMakePixmap(bp, WhitePixel, BlackPixel);
  37.     XFreeBitmap(bp);
  38.     pieces_masks[PAWN] = mask;
  39.  
  40.  
  41.     bp = XStoreBitmap(piece_width, piece_height, bishop_bits);
  42.     piece = XMakePixmap(bp, WhitePixel, BlackPixel);
  43.     XFreeBitmap(bp);
  44.     pieces_icons[BISHOP] = piece;
  45.  
  46.     bp = XStoreBitmap(piece_width, piece_height, bishop_mask_bits);
  47.     mask = XMakePixmap(bp, WhitePixel, BlackPixel);
  48.     XFreeBitmap(bp);
  49.     pieces_masks[BISHOP] = mask;
  50.  
  51.  
  52.     bp = XStoreBitmap(piece_width, piece_height, queen_bits);
  53.     piece = XMakePixmap(bp, WhitePixel, BlackPixel);
  54.     XFreeBitmap(bp);
  55.     pieces_icons[QUEEN] = piece;
  56.  
  57.     bp = XStoreBitmap(piece_width, piece_height, queen_mask_bits);
  58.     mask = XMakePixmap(bp, WhitePixel, BlackPixel);
  59.     XFreeBitmap(bp);
  60.     pieces_masks[QUEEN] = mask;
  61.  
  62.  
  63.     bp = XStoreBitmap(piece_width, piece_height, king_bits);
  64.     piece = XMakePixmap(bp, WhitePixel, BlackPixel);
  65.     XFreeBitmap(bp);
  66.     pieces_icons[KING] = piece;
  67.  
  68.     bp = XStoreBitmap(piece_width, piece_height, king_mask_bits);
  69.     mask = XMakePixmap(bp, WhitePixel, BlackPixel);
  70.     XFreeBitmap(bp);
  71.     pieces_masks[KING] = mask;
  72.  
  73.  
  74.     bp = XStoreBitmap(piece_width, piece_height, rook_bits);
  75.     piece = XMakePixmap(bp, WhitePixel, BlackPixel);
  76.     XFreeBitmap(bp);
  77.     pieces_icons[ROOK] = piece;
  78.  
  79.     bp = XStoreBitmap(piece_width, piece_height, rook_mask_bits);
  80.     mask = XMakePixmap(bp, WhitePixel, BlackPixel);
  81.     XFreeBitmap(bp);
  82.     pieces_masks[ROOK] = mask;
  83.  
  84.  
  85.     bp = XStoreBitmap(piece_width, piece_height, knight_bits);
  86.     piece = XMakePixmap(bp, WhitePixel, BlackPixel);
  87.     XFreeBitmap(bp);
  88.     pieces_icons[KNIGHT] = piece;
  89.  
  90.     bp = XStoreBitmap(piece_width, piece_height, knight_mask_bits);
  91.     mask = XMakePixmap(bp, WhitePixel, BlackPixel);
  92.     XFreeBitmap(bp);
  93.     pieces_masks[KNIGHT] = mask;
  94.  
  95.     bp = XStoreBitmap(icon_width, icon_height, icon_bits);
  96.     icon_pixmap = XMakePixmap(bp, WhitePixel, BlackPixel);
  97.     XFreeBitmap(bp);
  98.  
  99.     iconwindow = XCreateWindow(RootWindow, 0, 0,
  100.         icon_width, icon_height, 0, 0, 0);
  101.  
  102.     XSetIconWindow(window, iconwindow);
  103.     XSelectInput(iconwindow, ExposeWindow);
  104. }
  105.  
  106. redraw_pieces()
  107. {
  108.     int row, col, spot;
  109.  
  110.     for (row = 1; row <= 8; row++)
  111.     for (col = 1; col <= 8; col++) {
  112.         spot = 10 * row + col;
  113.         if (ghost[spot] && state == PLAYING)
  114.         redraw_ghost(spot);
  115.         else if (whose[spot] == ourcolor ||
  116.         (state != PLAYING && occupant[spot]))
  117.             redraw_piece(spot);
  118.     }
  119.     XPixSet(window, 0, 18, 64*8, 64, BlackPixel);
  120.     XPixSet(window, 0, TOPSPACE+64*8, 64*8, 64, BlackPixel);
  121.     for (spot = 0; spot < 32; spot+=2)
  122.     if (captured[spot])
  123.         redraw_captured(spot);
  124.     for (spot = 1; spot < 32; spot+=2)
  125.     if (captured[spot])
  126.         redraw_captured(spot);
  127. }
  128.  
  129. redraw_ghost(spot)
  130. {
  131.     Pixmap mask, icon;
  132.     register x, y;
  133.  
  134.     if (reverse) {
  135.     x = (8-spot%10) * 64;
  136.     y = (8-spot/10) * 64 + TOPSPACE;
  137.     } else {
  138.     x = (spot%10-1) * 64;
  139.     y = (spot/10-1) * 64 + TOPSPACE;
  140.     }
  141.     if (ghost[spot] == 0) {
  142.     fprintf("no ghost at %d\n", spot);
  143.     return;
  144.     }
  145.     mask = pieces_masks[ghost[spot]];
  146.     icon = pieces_icons[ghost[spot]];
  147.  
  148.     if (mask == 0) {
  149.     fprintf(stderr, "Invalid mask for location %d, occupied by %d\n",
  150.         spot, ghost[spot]);
  151.     return;
  152.     }
  153.     if (icon == 0) {
  154.     fprintf(stderr, "Invalid icon for location %d, occupied by %d\n",
  155.         spot, ghost[spot]);
  156.     return;
  157.     }
  158.     XPixmapPut(window, 0, 0, x, y, 64, 64,
  159.     icon, (theircolor==WHITE) ? GXor : GXandInverted, 1);
  160. }
  161.  
  162. redraw_piece(spot)
  163. {
  164.     Pixmap mask, icon;
  165.     register x, y;
  166.  
  167.     if (reverse) {
  168.     x = (8-spot%10) * 64;
  169.     y = (8-spot/10) * 64 + TOPSPACE;
  170.     } else {
  171.     x = (spot%10-1) * 64;
  172.     y = (spot/10-1) * 64 + TOPSPACE;
  173.     }
  174.     if (whose[spot] != ourcolor && state == PLAYING) {
  175.     fprintf(stderr, "cannot draw spot %d: occupied by %d\n",
  176.         spot, occupant[spot]);
  177.     return;
  178.     }
  179.     mask = pieces_masks[occupant[spot]];
  180.     icon = pieces_icons[occupant[spot]];
  181.  
  182.     if (mask == 0) {
  183.     fprintf(stderr, "Invalid mask for location %d, occupied by %d\n",
  184.         spot, occupant[spot]);
  185.     return;
  186.     }
  187.     if (icon == 0) {
  188.     fprintf(stderr, "Invalid icon for location %d, occupied by %d\n",
  189.         spot, occupant[spot]);
  190.     return;
  191.     }
  192.     if (ghost[spot])
  193.     redraw_pos(spot);
  194.     XPixmapPut(window, 0, 0, x, y, 64, 64,
  195.     mask, (whose[spot]==WHITE) ? GXor : GXandInverted, 1);
  196.     XPixmapPut(window, 0, 0, x, y,
  197.     64, 64, icon, (whose[spot]==WHITE) ? GXandInverted :
  198.     GXor, 1);
  199. }
  200.  
  201. redraw_captured(n)
  202. {
  203.     int piece = captured[n];
  204.     int color;
  205.     int x, y;
  206.     Pixmap mask, icon;
  207.  
  208.     if (n < 16) {
  209.     y = 18;
  210.     color = WHITE;
  211.     } else {
  212.     n -= 16;
  213.     y = 64+18 + 8*64;
  214.     color = BLACK;
  215.     }
  216.     if (reverse) {
  217.     if (color == WHITE)
  218.         y = 64+18 + 8*64;
  219.     else
  220.         y = 18;
  221.     }
  222.     x = n*32;
  223.     mask = pieces_masks[piece];
  224.     icon = pieces_icons[piece];
  225.     if (mask == 0 || icon == 0)
  226.     return;
  227.     if (color == ourcolor || state != PLAYING) {
  228.     XPixmapPut(window, 0, 0, x, y, 64, 64,
  229.         mask, (color==WHITE) ? GXor : GXandInverted, 1);
  230.     XPixmapPut(window, 0, 0, x, y,
  231.         64, 64, icon, (color==WHITE) ? GXandInverted :
  232.         GXor, 1);
  233.     } else
  234.     XPixmapPut(window, 0, 0, x, y, 64, 64, icon, GXor, 1);
  235. }
  236.  
  237. redraw_icon(reverse)
  238. bool reverse;
  239. {
  240.     XPixmapPut(iconwindow, 0, 0, 0, 0, icon_width, icon_height,
  241.         icon_pixmap, reverse ? GXcopyInverted : GXcopy, 1);
  242. }
  243.